# -*- coding: utf-8 -*-

from core.resources import CustomerModelResource
from apps.oms.models import Hawkeye
from apps.sys.models import DictData


class HawkeyeResouces(CustomerModelResource):

    @staticmethod
    def dehydrate_status(instance: Hawkeye):
        return DictData.objects.get("oms_hawkeye_status", value=instance.status).label

    @staticmethod
    def dehydrate_analysis(instance: Hawkeye):
        return (
            DictData.objects.get(
                type="oms_hawkeye_analysis", value=instance.analysis
            ).label
            if instance.analysis
            else ""
        )

    class Meta:
        model = Hawkeye
        fields = (
            "host__address",
            "title",
            "message",
            "create_time",
            "status",
            "analysis",
            "remark",
        )
        import_id_fields = "host__address"
